package cn.wen.yinxiu.member.service.impl;

import cn.wen.yinxiu.common.enums.DelEnum;
import cn.wen.yinxiu.common.enums.StatusEnum;
import cn.wen.yinxiu.member.entity.UserGroupRelationEntity;
import cn.wen.yinxiu.member.service.UserGroupRelationService;
import cn.wen.yinxiu.member.vo.GroupInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.toolkit.Query;

import cn.wen.yinxiu.member.dao.GroupDao;
import cn.wen.yinxiu.member.entity.GroupEntity;
import cn.wen.yinxiu.member.service.GroupService;


@Service("groupService")
public class GroupServiceImpl extends ServiceImpl<GroupDao, GroupEntity> implements GroupService {

    @Autowired
    private GroupDao groupDao;

    @Autowired
    private UserGroupRelationService userGroupRelationService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GroupEntity> page = this.page(
                new Query<GroupEntity>().getPage(params),
                new QueryWrapper<GroupEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public GroupEntity queryTalkBoxById(Long talkId) {
        return groupDao.selectById(talkId);
    }

    @Override
    public List<GroupInfo> queryUserGroupList(Long userId) {
        return groupDao.selectUserGroupListByUserId(userId,
                StatusEnum.NORMAL_USE.code(), DelEnum.NORMAL.code());
    }

    @Override
    public List<Long> queryUserGroupsIdList(Long userId) {
        return groupDao.selectUserGroupIdList(userId,
                StatusEnum.NORMAL_USE.code(), DelEnum.NORMAL.code());
    }

    @Override
    public boolean exitGroup(Long userId, Long groupId) {
        return userGroupRelationService.exitGroup(userId, groupId);
    }

}